function newPos = shipFerguson(graph, currentPos, lastPos, p)
%% This function is used to simulate the ship by Ferguson. The next
%% position depends on the given p.
possible = [];

%save all possible next positions in possible
for i=1:length(graph)
    if(i~=lastPos(1) && graph(currentPos,i) == 1)
        possible = [possible, i];
    end
end

%calculate the new position of the ship
if(lastPos(1) <=0)
    newPos = possible(ceil(rand(1)*length(possible)));
else
    random = rand(1);
    newPos = lastPos(1);
    for i=1:length(possible)
        if(random<i*p)
            newPos = possible(i);
            break;
        end
    end
end
